/**
 * 
 */
package vy.org.app.page.employee;

/**
 * @author Ravi Shankar
 *
 */
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vy.dal.dao.VyEmployeeDAO;
import org.vy.dal.dao.VyEmployeeDO;

import vy.org.app.common.AppConstants;
import vy.org.app.common.BaseAction;
import vy.org.app.common.ModeEnum;
import vy.org.app.common.ModuleEnum;
import vy.org.util.DateUtil;

public class MntnEmployeeAction extends BaseAction {

	@Override
	public ActionForward executeAction(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {

		MntnEmployeeForm form = (MntnEmployeeForm) actionForm;
		VyEmployeeDO dto = new VyEmployeeDO();

		if (form != null && form.getMode() != null) {
			if (ModeEnum.SEARCH.getName().equals(form.getMode())) {
				if (form.getVyId() != null && !"".equals(form.getVyId().trim())) {
					dto.setVyId(form.getVyId());
				}
				if (form.getResponsibilityid() != null
						&& !"".equals(form.getResponsibilityid().trim())) {
					dto.setEmployeeId(form.getResponsibilityid());
				}
				if (form.getFullName() != null
						&& !"".equals(form.getFullName().trim())) {
					dto.setFullName(form.getFullName());
				}
				if (form.getWorkScope() != null
						&& !"".equals(form.getWorkScope().trim())) {
					dto.setWorkScope(form.getWorkScope());
				}
				if (form.getDesignationid() != null
						&& !"".equals(form.getDesignationid().trim())) {
					dto.setDesignationId(form.getDesignationid());
				}
				if (form.getRoles() != null
						&& !"".equals(form.getRoles().trim())) {
					dto.setRolesResponsibility(form.getRoles());
				}
				if (form.getWorkCitycode() != null
						&& !"".equals(form.getWorkCitycode().trim())) {
					dto.setWorkLocation(form.getWorkCitycode());
				}
				if (form.getSantSamajId() != null
						&& !"".equals(form.getSantSamajId().trim())) {
					dto.setSantSamajId(form.getSantSamajId());
				}
				if (form.getAshramid() != null
						&& !"".equals(form.getAshramid().trim())) {
					dto.setAshramId(form.getAshramid());
				}
				if (form.getStartDate() != null
						&& !"".equals(form.getStartDate().trim())) {
					dto.setStartDate(form.getStartDate());
				}
				if (form.getEndDate() != null
						&& !"".equals(form.getEndDate().trim())) {
					dto.setEndDate(form.getEndDate());
				}
				if (form.getLastUpdatedBy() != null
						&& !"".equals(form.getLastUpdatedBy().trim())) {
					dto.setLastUpdatedBy(form.getLastUpdatedBy());
				}
				if (form.getLastUpdatedOn() != null
						&& !"".equals(form.getLastUpdatedOn().trim())) {
					dto.setLastUpdatedOn(DateUtil.standardDate(form.getLastUpdatedOn()));
				}
				try {
					request.setAttribute(AppConstants.RESULT, VyEmployeeDAO
							.findByParam(dto));
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (ModeEnum.ADD.getName().equals(form.getMode())) {
				if (form.getVyId() != null && !"".equals(form.getVyId().trim())) {
					dto.setVyId(form.getVyId());
				}
				if (form.getResponsibilityid() != null
						&& !"".equals(form.getResponsibilityid().trim())) {
					dto.setEmployeeId(form.getResponsibilityid());
				}
				if (form.getFullName() != null
						&& !"".equals(form.getFullName().trim())) {
					dto.setFullName(form.getFullName());
				}
				if (form.getWorkScope() != null
						&& !"".equals(form.getWorkScope().trim())) {
					dto.setWorkScope(form.getWorkScope());
				}
				if (form.getDesignationid() != null
						&& !"".equals(form.getDesignationid().trim())) {
					dto.setDesignationId(form.getDesignationid());
				}
				if (form.getRoles() != null
						&& !"".equals(form.getRoles().trim())) {
					dto.setRolesResponsibility(form.getRoles());
				}
				if (form.getWorkCitycode() != null
						&& !"".equals(form.getWorkCitycode().trim())) {
					dto.setWorkLocation(form.getWorkCitycode());
				}
				if (form.getSantSamajId() != null
						&& !"".equals(form.getSantSamajId().trim())) {
					dto.setSantSamajId(form.getSantSamajId());
				}
				if (form.getAshramid() != null
						&& !"".equals(form.getAshramid().trim())) {
					dto.setAshramId(form.getAshramid());
				}
				if (form.getStartDate() != null
						&& !"".equals(form.getStartDate().trim())) {
					dto.setStartDate(form.getStartDate());
				}
				if (form.getEndDate() != null
						&& !"".equals(form.getEndDate().trim())) {
					dto.setEndDate(form.getEndDate());
				}
				if (form.getLastUpdatedBy() != null
						&& !"".equals(form.getLastUpdatedBy().trim())) {
					dto.setLastUpdatedBy(form.getLastUpdatedBy());
				}
				if (form.getLastUpdatedOn() != null
						&& !"".equals(form.getLastUpdatedOn().trim())) {
					dto.setLastUpdatedOn(DateUtil.standardDate(form.getLastUpdatedOn()));
				}
				try {
					VyEmployeeDAO.insert(dto);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return mapping.findForward("success");
	}

	@Override
	protected ModuleEnum getModuleId() {
		return ModuleEnum.SEARCH_EMPLOYEE;
	}

}
